package com.ybkj.daijia.server.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.BooleanUtils;

/**
 * 管理员
 *
 * @author Shine
 */
public class Admin extends Base implements Serializable {

    public static final String SALT_KEY = "akoaix";
    private static final long serialVersionUID = -1308795024262635690L;
    private String username;

    @JsonIgnore
    private String password;

    private Boolean isInternal;// 是否内置

    private Boolean isLocked;// 是否锁定、冻结

    private Long companyId;

    private Company company;

    private List<Role> roles;

    private String phone;//手机号码 用于接收验证码

    private Integer messageTime;//当日短信验证码发送次数

    @JsonIgnore
    private String vcode; // 验证码

    @JsonIgnore
    private Date expired;// 验证码发送时间

    @JsonIgnore
    private boolean phoneLogin;//是否启用短信登录

    @JsonIgnore
    private String loginToken;//登录标识

    @JsonIgnore
    private int loginFailed;//登录失败次数

    @JsonIgnore
    private Date passwordDate;//密码过期时间


    public Date getPasswordDate() {
        return passwordDate;
    }

    public void setPasswordDate(Date passwordDate) {
        this.passwordDate = passwordDate;
    }

    public int getLoginFailed() {
        return loginFailed;
    }

    public void setLoginFailed(int loginFailed) {
        this.loginFailed = loginFailed;
    }

    public String getLoginToken() {
        return loginToken;
    }

    public void setLoginToken(String loginToken) {
        this.loginToken = loginToken;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getVcode() {
        return vcode;
    }

    public void setVcode(String vcode) {
        this.vcode = vcode;
    }

    public Date getExpired() {
        return expired;
    }

    public void setExpired(Date expired) {
        this.expired = expired;
    }

    public boolean isPhoneLogin() {
        return phoneLogin;
    }

    public void setPhoneLogin(boolean phoneLogin) {
        this.phoneLogin = phoneLogin;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean getIsInternal() {
        return BooleanUtils.toBoolean(isInternal);
    }

    public void setIsInternal(Boolean isInternal) {
        this.isInternal = isInternal;
    }

    public Boolean getIsLocked() {
        return BooleanUtils.toBoolean(isLocked);
    }

    public void setIsLocked(Boolean isLocked) {
        this.isLocked = isLocked;
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public boolean getPasswordExpired() {
        if (null == passwordDate) {
            return Boolean.FALSE;
        }
        if (((System.currentTimeMillis() - passwordDate.getTime()) / (1000 * 60 * 60 * 24)) >= 30) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Admin other = (Admin) obj;
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        return true;
    }
}
